package models

import (
	"time"
)

type User struct {
	Model `gorm:"unique_index"`
	Name string `gorm:"unique_index" json:"name"`
	Email string `gorm:"unique_index" json:"email"`
	Pwd string  `json:"_"`
	Avartar string `json:"avartar"`
	Role  int    `json:"role"`//0管理员1是正常用户  `gorm:"default:1"`    0 "" 时数据库存入1
}

func QueryUserByUsernamePwd(email,pwd string)(user User,err error){
	return user,db.Where("email = ? and pwd = ?",email,pwd).Take(&user).Error
}

func QueryUserByName(name string)(user User,err error){
	return user,db.Where("name = ? ",name).Take(&user).Error
}

func QueryUserByEmail(email string)(user User,err error){
	return user,db.Where("email = ? ",email).Take(&user).Error
}

func SaveUser(user *User) error{
	return db.Save(user).Error
}

type Model struct {
	ID        uint `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt *time.Time `sql:"index" json:"deleted_at"`
}